using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace Repo {
	public class SQL {
		string _cs;
		public SQL(string cs) { _cs=cs; }
		public DataSet QuerySet(string sql,params object[] args) {
			DataSet set=new DataSet();
			using(SqlDataAdapter adp=new SqlDataAdapter(string.Format(sql,args),_cs))
			{
				adp.Fill(set);
			}
			return set;
		}
		public DataTable Query(string sql,params object[] args) {
			DataTable tab=new DataTable();
			if(args.Length>0)
				sql=string.Format(sql,args);
			using(SqlDataAdapter adp=new SqlDataAdapter(sql,_cs))
				adp.Fill(tab);
			return tab;
		}
		public int NonQuery(string sql,params object[] args) {
			int ret=-1;
			string sqlCmd=string.Format(sql,args);
			using(SqlConnection con=new SqlConnection(_cs))
			using(SqlCommand cmd=new SqlCommand(sqlCmd,con))
			{
				con.Open();
				ret=cmd.ExecuteNonQuery();
				con.Close();
			}
			return ret;
		}
	}
}
